/*    */ package com.cr.common.utils;
/*    */ 
/*    */ import java.io.FileNotFoundException;
/*    */ import java.io.FileWriter;
/*    */ import java.io.IOException;
/*    */ import java.io.InputStream;
/*    */ import java.util.LinkedHashMap;
/*    */ import java.util.Map;
/*    */ import org.yaml.snakeyaml.DumperOptions;
/*    */ import org.yaml.snakeyaml.Yaml;
/*    */ @SuppressWarnings("unchecked")
/*    */ public class YamlUtil {
/*    */   public static Map<?, ?> loadYaml(String fileName) throws FileNotFoundException {
/* 22 */     InputStream in = YamlUtil.class.getClassLoader().getResourceAsStream(fileName);
/* 23 */     return MyStringUtils.isNotEmpty(fileName) ? (LinkedHashMap)(new Yaml()).load(in) : null;
/*    */   }
/*    */   
/*    */   public static void dumpYaml(String fileName, Map<?, ?> map) throws IOException {
/* 28 */     if (MyStringUtils.isNotEmpty(fileName)) {
/* 30 */       FileWriter fileWriter = new FileWriter(YamlUtil.class.getResource(fileName).getFile());
/* 31 */       DumperOptions options = new DumperOptions();
/* 32 */       options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
/* 33 */       Yaml yaml = new Yaml(options);
/* 34 */       yaml.dump(map, fileWriter);
/*    */     } 
/*    */   }
/*    */   
/*    */   public static Object getProperty(Map<?, ?> map, Object qualifiedKey) {
/* 40 */     if (map != null && !map.isEmpty() && qualifiedKey != null) {
/* 42 */       String input = String.valueOf(qualifiedKey);
/* 43 */       if (!"".equals(input)) {
/* 45 */         if (input.contains(".")) {
/* 47 */           int index = input.indexOf(".");
/* 48 */           String left = input.substring(0, index);
/* 49 */           String right = input.substring(index + 1, input.length());
/* 50 */           return getProperty((Map<?, ?>)map.get(left), right);
/*    */         } 
/* 52 */         if (map.containsKey(input))
/* 54 */           return map.get(input); 
/* 58 */         return null;
/*    */       } 
/*    */     } 
/* 62 */     return null;
/*    */   }
/*    */   
/*    */   public static void setProperty(Map<Object, Object> map, Object qualifiedKey, Object value) {
/* 68 */     if (map != null && !map.isEmpty() && qualifiedKey != null) {
/* 70 */       String input = String.valueOf(qualifiedKey);
/* 71 */       if (!input.equals(""))
/* 73 */         if (input.contains(".")) {
/* 75 */           int index = input.indexOf(".");
/* 76 */           String left = input.substring(0, index);
/* 77 */           String right = input.substring(index + 1, input.length());
/* 78 */           setProperty((Map<Object, Object>)map.get(left), right, value);
/*    */         } else {
/* 82 */           map.put(qualifiedKey, value);
/*    */         }  
/*    */     } 
/*    */   }
/*    */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\lib\creditorRights-common-4.7.0.jar!\com\cr\commo\\utils\YamlUtil.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */